package datasource;

import org.junit.Test;

import java.sql.*;

/**
 * @author: feiwang_6
 * @create: 2020/5/28 16:01
 * @description:
 */
public class DatasourceTest {
    private String driverName = "com.mysql.jdbc.Driver";
    private String url = "jdbc:mysql://10.2.98.74:3306/pis_ccs";
    private String user = "tujia";
    private String password = "tujia";
    
    @Test
    public void testSelect() throws SQLException {
        Connection con = null;
        try {
            //1.加载驱动程序
            Class.forName(driverName);
            //2.获取连接
            con = DriverManager.getConnection(url,user,password);
            //3.创建statement对象
            Statement statement = con.createStatement();
            String sql = "SELECT * FROM leaf_alloc WHERE biz_tag = 'test_biz'";
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()){
                long id = resultSet.getLong("id");
                int max_id = resultSet.getInt("max_id");
                String biz_tag = resultSet.getString("biz_tag");
                System.out.println(id + "  " + max_id + " " + biz_tag);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            con.close();
        }
    }
}
